from celery import Celery
from kombu import Queue
app = Celery('two',  broker='redis://localhost:6379/3',backend='redis://localhost:6379/3')
# 创建任务队列
app.conf.task_queues = (
    Queue('default', routing_key='task.#'),  # 默认队列
    Queue('email_queue', routing_key='email.*'),  # 邮件队列
    Queue('sms_queue', routing_key='sms.*'),  # 短信队列
)
# 创建任务路由
app.conf.task_routes = {
    'task.add': {'queue': 'default', 'routing_key': 'task.add'},
    'task.send_email': {'queue': 'email_queue', 'routing_key': 'email.send'},
    'task.send_sms': {'queue': 'sms_queue', 'routing_key': 'sms.send'},
}
# 定义任务
@app.task
def send_email(to, content):
    """发送邮件任务"""
    print(f"发送邮件到{to}，内容：{content}")

@app.task
def send_sms(phone, content):
    """发送短信任务"""
    print(f"发送短信到{phone}，内容：{content}")